import ResourceManager

class Animation(object):

   NO_KEY_FRAME = -1
   ALL_KEY_FRAMES = -2

   
   def __init__(self, animation, timing, keyFrame):
      self.animation = animation
      self.ANIMATION_TIMING = timing
      self.keyFrame = keyFrame
      
      self.currentFrame = 0
      self.tickCount = 0

      self.image = self.animation[self.currentFrame]
      self.rect = self.image.get_rect()

      self.animationComplete = False


   def update(self):
      self.animationComplete = False
      if self.tickCount == self.ANIMATION_TIMING:
         
         #change frame
         self.tickCount = 0
         self.currentFrame += 1
         if self.currentFrame == len(self.animation):
            self.currentFrame = 0
            self.animationComplete = True
         self.image = self.animation[self.currentFrame]
         return True
      else:
         self.tickCount += 1
         return False

   def isKeyFrame(self):
      return (self.keyFrame == Animation.ALL_KEY_FRAMES or
              self.currentFrame == self.keyFrame) \
              and self.tickCount == 0
         
   def isComplete(self):
      return self.animationComplete
